home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 4
/
United Public Domain Gold 4.iso
/
scope
/
sc004.dms
/
sc004.adf
/
ForEach
/
foreach.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-04-26
|
1KB
|
64 lines
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <libraries/dosextens.h>
/* Compiled with Lattice v4.0 */
void main(argc, argv)
int argc;
char **argv;
{
char *filestring;
char *commandstring;
int error;
int i;
struct FILEINFO info;
int attr=0;
/* One could really look more at the arguments more here... */
if (argc<3)
{
printf("Usage is %ls <filepattern> <command> <extra args>\n", argv[0]);
exit(0);
}
/* Get filepattern and command to apply */
filestring=strdup(argv[1]);
commandstring=strdup(argv[2]);
/* Make sure command gets all the supplied args.. */
for(i=3;i<argc;i++)
{
strcat(commandstring, " ");
strcat(commandstring, argv[i]);
}
strcat(commandstring, " ");
if((error=dfind(&info, filestring, attr))!=0)
{
printf("\nNo file named %ls", filestring);
exit(0);
}
do
if(Execute(strcat(strdup(commandstring), info.fib_FileName),0,0)==0)
{
printf("Execute failed with command %ls\n and filename %ls\n",
commandstring, info.fib_FileName);
exit(0);
}
/* First strdup to create an untouched copy of commandstring, then */
/* execute it with current filename. */
while(!dnext(&info)); /* Nice test. */
printf("\nDone!\n");
}